include("../static/js/config.js");
include("../static/js/common.js");

$(function () {

    $("#submit").click(function () {
        var loadIdx = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });

        var username = $("#username").val();
        var password = $("#password").val();


        baseRequest("/login", {username: username, password:password}, function (data) {
            if (data.code === 200){
                layer.close(loadIdx);
                layer.msg('登录成功', {time: 3000, icon:6});

                window.localStorage.setItem('token', data.data.token);
                window.localStorage.setItem('username', data.data.username);

                asyncRequest("/open/resource/menu", {}, function (res) {
                    if (res.code === 200){
                        window.localStorage.setItem('menu', JSON.stringify(res.data));
                    }
                });

                setTimeout(function () {
                    window.location.href = config.url + "/index.html";
                }, 3000);
            } else {
                layer.msg(data.msg, {time: 3000, icon:5});
            }
        })
    })
})